<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Models\SLessonInfo;
use App\Models\SLessonFeedback;
use App\Models\SStuTaskInfo;


class AutoAddStuTask implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    var $cb_id;
    var $adminid;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct( $cb_id, $adminid)
    {
        //
        $this->cb_id   = $cb_id;
        $this->adminid = $adminid;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        logger('cb_id:'.$this->cb_id);
        logger('adminid:'.$this->adminid);

        $fb_info = SLessonFeedback::find($this->cb_id);
        $lesson = SLessonInfo::find($fb_info->lesson_id );
        SStuTaskInfo::firstOrCreate([
            'user_id' => $lesson->user_id,
            'teacher_id' => $lesson->teacher_id,
            'admin_id' => $this->adminid,
            'feed_back_id' => $fb_info->id,
        ],[
            'status' => 0,

        ]);
        
    }

}
